package com.me.libgdx_test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class ClassPlayerAttackMod {
	//Modifiers for atk, hit, kill, and death
	//Attack modifier: 1 hit KO monsters lower level, 25% damage monsters higher level, 25% to all nearby enemies, hits raise atk by 12%,
	//	10% change turning enemy into potion, atks between 70%-110%, 10% chance to turn enemy into wall, atks poison enemy, +25% enemy atk,
	//  killing magical enemy restores 50% health, 200% dmg to undead, atks require 1 gold, 25% atk vs. living, -25% vs undead, +1 player atk,
	//  -1/2 gold, x2.5 gold added to dmg, adds difference between mana and health to attack, +50% dmg monsters same lvl, adds 1.5 mana to dmg,
	//	drains 1/2 mana, 5% life steal, +75% damage when health below 25%
	//Defense modifier: does 1 magic damage per level when hit
	//Kill modifier: 10% damage next hit, +1 gold per monster lvl, 10% max mana, first strike, +1 exp, +20 gold
	//Death modifier: Does 300% damage after death, Cannot die with full health
	ArrayList<String> attack_mods;
	Random random = new Random(System.currentTimeMillis());
	private int kills, deaths;
	ClassPlayerAttackMod(String...attack_mods){
		this.attack_mods = new ArrayList<String>(Arrays.asList(attack_mods));
		kills = 0;
		deaths = 0;
	}
	//These functions are experimental for the player info hud
	public float undead_bonus(){
		float bonus = 0;
		for(String attack_mod: attack_mods){
			if(attack_mod.equals("-15%_undead")){
				bonus += -.15f;
			}
			if(attack_mod.equals("-25%_undead")){
				bonus += -.25f;
			}
			if(attack_mod.equals("+25%_undead")){
				bonus += .25f;
			}
			if(attack_mod.equals("+45%_undead")){
				bonus += .45f;
			}
			if(attack_mod.equals("+85%_undead")){
				bonus += .85f;
			}
			if(attack_mod.equals("+160%_undead")){
				bonus += 1.6f;
			}
			if(attack_mod.equals("+200%_undead")){
				bonus += 2f;
			}
		}
		return bonus;
	}
	public float living_bonus(){
		float bonus = 0;
		for(String attack_mod: attack_mods){
			if(attack_mod.equals("-15%_living")){
				bonus += -.15f;
			}
			if(attack_mod.equals("-25%_living")){
				bonus += -.25f;
			}
			if(attack_mod.equals("+25%_living")){
				bonus += .25f;
			}
			if(attack_mod.equals("+45%_living")){
				bonus += .45f;
			}
			if(attack_mod.equals("+85%_living")){
				bonus += .85f;
			}
			if(attack_mod.equals("+160%_living")){
				bonus += 1.6f;
			}
			if(attack_mod.equals("+200%_living")){
				bonus += 2f;
			}
		}
		return bonus;
	}
	//Attack modifier: 25% to all nearby enemies, hits raise atk by 12%
	public void get_attack_mod_beginning(ClassCharacterPlayer player, ClassCharacterEnemy enemy){
		for(String attack_mod: attack_mods){
			if(attack_mod.equals("enemy_stronger")){
				enemy.attack+=(enemy.attack*.25);
			}
			if(attack_mod.equals("40%_dbl_dodge_status")){
				if(player.roll(40, 100) && player.has_status_benefit()){
					player.dbl_hit_bonus += .4f;
					player.dodge_bonus += .4f;
				}
			}
			if(attack_mod.equals("45%_full_health")){
				if(player.get_player_variable("current_health") == player.get_max_health()){
					player.attack_bonus += .45;
				}else{
					player.attack_bonus -= .30;
				}
			}
			if(attack_mod.equals("25%_atk_higher")){
				if(player.get_player_variable("level") < enemy.level){
					player.attack_bonus += .25;
				}
			}
			/*
			 * "+45% Atk vs. Living","+85% Atk vs. Living","+160% Atk vs. Living"
			 */
			if(attack_mod.equals("-15%_living")){
				if(!enemy.get_attack_mod("Undead")){
					player.attack_bonus -= .15;
				}
			}
			if(attack_mod.equals("-25%_living")){
				if(!enemy.get_attack_mod("Undead")){
					player.attack_bonus -= .25;
				}
			}
			if(attack_mod.equals("+25%_living")){
				if(!enemy.get_attack_mod("Undead")){
					player.attack_bonus += .25;
				}
			}
			if(attack_mod.equals("+45%_living")){
				if(!enemy.get_attack_mod("Undead")){
					player.attack_bonus += .45;
				}
			}
			if(attack_mod.equals("+85%_living")){
				if(!enemy.get_attack_mod("Undead")){
					player.attack_bonus += .85;
				}
			}
			if(attack_mod.equals("+160%_living")){
				if(!enemy.get_attack_mod("Undead")){
					player.attack_bonus += 1.6;
				}
			}
			if(attack_mod.equals("-15%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus -= .15;
				}
			}
			if(attack_mod.equals("-25%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus -= .25;
				}
			}
			if(attack_mod.equals("+25%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus += .25;
				}
			}
			if(attack_mod.equals("+45%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus += .45;
				}
			}
			if(attack_mod.equals("+85%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus += .85;
				}
			}
			if(attack_mod.equals("+160%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus += 1.6;
				}
			}
			if(attack_mod.equals("+200%_undead")){
				if(enemy.get_attack_mod("Undead")){
					player.attack_bonus += 2;
				}
			}
			if(attack_mod.equals("+1_atk")){
				player.set_player_variable("attack", player.get_player_variable("attack")+1);
			}
			if(attack_mod.equals("12%_hit_atk_bonus")){
				player.on_step_bonus += .12f;
			}
			if(attack_mod.equals("75%_atk_health_low")){
				if(player.get_player_variable("current_health") < player.get_max_health()/4){
					player.attack_bonus += .75;
				}
			}
			if(attack_mod.equals("1.5_mana_dmg")){
				player.concrete_attack_bonus += player.get_player_variable("current_mana") * 1.5;
				player.set_player_variable("current_mana", (int) player.get_player_variable("current_mana")/2);
			}
			if(attack_mod.equals("50%_atk_same")){
				if(player.get_player_variable("level") == enemy.level){
					player.attack_bonus += .50;
				}
			}
			if(attack_mod.equals("mana_health_difference")){
				player.concrete_attack_bonus += player.get_player_variable("current_mana") - player.get_player_variable("current_health");
			}
			if(attack_mod.equals("x2.5_gold_dmg")){
				player.concrete_attack_bonus += player.get_player_variable("gold") * 2.5;
				player.set_player_variable("gold", (int) player.get_player_variable("gold")/2);
			}
			if(attack_mod.equals("1_hit_ko_lower")){
				if(player.get_player_variable("level") > enemy.level){
					enemy.current_health = 0;
				}
			}
		}
		//player.set_player_variable("current_health", (int)(player.get_player_variable("current_health") + enemy.max_health * player.life_steal));
	}
	public int get_attack_mod_middle(ClassCharacterPlayer player, ClassCharacterEnemy enemy, int attack){
		int current_attack = attack;
		if(player.get_contracted_mod("Blind")){
			current_attack = random.nextInt(10)>8?0:current_attack;
		}
		for(String attack_mod: attack_mods){
			if(attack_mod.equals("gambler")){
				float range = player.upper_bounds - player.lower_bounds;
				int range_attack = random.nextInt((int) (current_attack * range));
				current_attack = (int) (current_attack * player.lower_bounds + range_attack);
			}
			if(attack_mod.equals("need_gold")){
				if(player.get_player_variable("gold")>0){
					player.set_player_variable("gold", player.get_player_variable("gold")-1);
				}else{
					//No gold. Only the enemy attacks
					return 0;
				}
			}
		}
		if(player.roll((int)(player.get_player_variable_float("death_gaze")*100),100)){
			//Instead of turning enemies into stone we are just gonna weaken them
			enemy.set_contracted_mod("Weakness", true);
			enemy.set_contracted_mod("Poison", true);
		}
		player.set_player_variable("current_health", player.get_player_variable("current_health") + (int) (player.get_player_variable_float("life_steal") * current_attack));
		return current_attack;
	}
	public void get_attack_mod_end(ClassCharacterPlayer player, ClassCharacterEnemy enemy, int health_before_attack){
		if(player.get_player_variable("current_health") < 1){
			player.add_god_action("got_killed");
			deaths++;
		}
		if(enemy.current_health < 1){
			player.add_god_action("did_killed");
			kills++;
			if(enemy.get_attack_mod("Magic Attack")){
				player.add_god_action("magic_enemy");
			}else{
				player.add_god_action("phys_enemy");
			}
			if(enemy.get_attack_mod("Undead")){
				player.add_god_action("kill_undead");
			}else{
				player.add_god_action("kill_living");
			}
		}
		
		for(String attack_mod:attack_mods){
			if(attack_mod.equals("+1_atk_death")){
				if(player.get_player_variable("current_health") < 1){
					player.set_player_variable("attack", player.get_player_variable("attack")+1);
				}
			}
			if(attack_mod.equals("+3_atk_death")){
				if(player.get_player_variable("current_health") < 1){
					player.set_player_variable("attack", player.get_player_variable("attack")+3);
				}
			}
			if(attack_mod.equals("+5_atk_death")){
				if(player.get_player_variable("current_health") < 1){
					player.set_player_variable("attack", player.get_player_variable("attack")+5);
				}
			}
			if(attack_mod.equals("-50%_mana_death")){
				player.set_player_variable("current_mana", player.get_player_variable("current_mana")/2);
			}
			if(attack_mod.equals("cant_die_full_health")){
				if(player.get_max_health() == health_before_attack && player.get_player_variable("current_health") < 1){
					//If the player died, but had full health before, bring the player back to life...
					player.set_player_variable("current_health", 1);
				}
			}
			if(attack_mod.equals("magic_heal")){
				if(enemy.get_attack_mod("Magic Attack")){
					player.set_player_variable("current_health", (int)(player.get_player_variable("current_health")+player.get_max_health()*.2));
				}
			}
			if(attack_mod.equals("10%_enemy_potion")){
				if(enemy.current_health < 1 && random.nextInt(10)>8){
					player.set_player_variable("health_potions", player.get_player_variable("health_potions")+1);
				}
			}
			if(attack_mod.equals("10%_atk_kill")){
				if(enemy.current_health < 1){
					player.on_kill_bonus += .1;
				}
			}
			if(attack_mod.equals("10%_hp_kill")){
				if(enemy.current_health < 1){
					player.set_player_variable("current_health", 
							(int)(player.get_player_variable("current_health") + player.get_player_variable("max_health") * .1));
				}
			}
			if(attack_mod.equals("40%_hp_kill")){
				if(enemy.current_health < 1){
					player.set_player_variable("current_health", 
							(int)(player.get_player_variable("current_health") + player.get_player_variable("max_health") * .4));
				}
			}
			if(attack_mod.equals("+2_hp_kill")){
				if(enemy.current_health < 1){
					player.set_player_variable("max_health", player.get_player_variable("max_health") + 2);
				}
			}
			if(attack_mod.equals("+5_hp_kill")){
				if(enemy.current_health < 1){
					player.set_player_variable("max_health", player.get_player_variable("max_health") + 5);
				}
			}
			if(attack_mod.equals("10%_max_mana")){
				if(enemy.current_health < 1){
					player.set_player_variable("current_mana", 
							(int)( player.get_player_variable("current_mana") + player.get_player_variable("current_mana") * .1 ));
				}
			}
			if(attack_mod.equals("+20_gold_enemy_death")){
				if(enemy.current_health < 1){
					player.set_player_variable("gold", player.get_player_variable("gold") + 20);
				}
			}
			if(attack_mod.equals("gold_enemy_death")){
				if(enemy.current_health < 1){
					player.set_player_variable("gold", player.get_player_variable("gold") + player.get_player_variable("level"));
				}
			}
			if(attack_mod.equals("300%_death")){
				if(player.get_player_variable("current_health") < 1){
					player.attack_bonus += 3;
				}
			}
			if(attack_mod.equals("kill_first_strike") && (player.current_health > 0 || player.get_contracted_mod("Extra Life"))){
				if(enemy.current_health < 1){
					player.set_contracted_mod("First Strike", true);
				}
			}
			if(attack_mod.equals("2_mana_enemy_death")){
				if(enemy.current_health < 1){
					player.set_player_variable("current_mana", player.get_player_variable("current_mana") + 2);
				}
			}
			if(attack_mod.equals("1_exp_death")){
				if(enemy.current_health < 1){
					player.add_exp(1);
				}
			}
		}
		if(enemy.current_health > 0){
			player.on_kill_bonus = 0;
		}
	}
	public void get_attack_mod_onhit(ClassCharacterPlayer player, ClassCharacterEnemy enemy, int current_attack){
		for(String attack_mod:attack_mods){
			if(attack_mod.equals("mgc_atk_returned")){
				enemy.current_health -= player.get_player_variable("level");
			}
		}
	}
	public void increment_kill(){
		kills++;
	}
	public int get_kills(){
		return kills;
	}
	public int get_deaths(){
		return deaths;
	}
}
